function [lambdat_hat, Vnt_hat, betat_hat, yt_hat, R2_t] = AJX_HF(dFt_j, dPt_j, dPt_jp1, beta_J, qn, Delta_n, nobs, Tn)

    
    K         =     size(dFt_j,1);
    M         =     size(dPt_j,1);
    H         =     size(beta_J,2);

    un        =     3;

    vn        =     10000*log(1/((Tn)*Delta_n));
      
    dPtj_NaN  =     (sum(isnan(dPt_j),2)>0);
    
    beta_J_hat_j  =   beta_J.*~dPtj_NaN;
    
    dPt_j(isnan(dPt_j)) = 0;
    dPt_jp1(isnan(dPt_jp1)) = 0;
    
    dFt_cont_ix_j = fn_cont_ix(un, 0.47, dFt_j, Delta_n, qn/nobs, nobs);
    dPt_cont_ix_j = fn_cont_ix(un, 0.47, dPt_j, Delta_n, qn/nobs, nobs);
    
    % Retain only continuous movements in factors
    dFt_j = dFt_j.*dFt_cont_ix_j;
    dPt_j = dPt_j.*dPt_cont_ix_j;
    
    
    cF_t    = 1/(qn*Delta_n) * dFt_j*(dFt_j');
    gamma_t = 1/(qn*Delta_n) * (dPt_j*dFt_j');
        
    if min(eig(cF_t)) > 1/vn
        beta_C_hat_j = gamma_t * inv(cF_t);
    else
        beta_C_hat_j = zeros(M,K);
    end
    
    for i = 1:M
        if dPtj_NaN(i) > 0
            beta_C_hat_j(i,:) = zeros(1,K);
        end
    end
    
    beta_hat = [beta_C_hat_j, beta_J_hat_j];
    
    b_hat = beta_hat' * beta_hat;

    if min(eig(b_hat)) > 1/vn
        eta_hat = inv(b_hat) * beta_hat';
    else
        eta_hat = zeros(K+H,M);
    end
    
    lambdat_hat = eta_hat * sum(dPt_jp1,2);
    R2_t        = (lambdat_hat'*(beta_hat'))*(lambdat_hat'*(beta_hat'))'/((sum(dPt_jp1,2)')*(sum(dPt_jp1,2)));
    Vnt_hat     = eta_hat * sum(dPt_jp1,2)*(sum(dPt_jp1,2)') * (eta_hat');
    betat_hat   = beta_hat;
    yt_hat      = sum(dPt_jp1,2);

end
